<template>
  <div>
    <el-table :data="cutObj.records" style="width: 100%;height:200px;">
      <el-table-column prop="name" label="客户名称" width="300"/>
      <el-table-column prop="principal" label="负责人" width="300"/>
      <el-table-column prop="manage" label="经营范围" width="200"/>
      <el-table-column fixed="right" label="操作" width="250">
        <template #default="scope">
          <el-button type="primary" @click="find(scope.row.id)">查看</el-button>
          <el-button type="primary" @click="update(scope.row.id)">修改信息</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        v-model:page-size="cutObj.size"
        background
        :total="cutObj.total"
        @current-change="findByItem"
    />
    <el-row>
      <el-col :span="5">客户名称:<input type="text " v-model="findObj.name" style="width: 80px"></el-col>
      <el-col :span="5">经营范围:<input type="text " v-model="findObj.manage" style="width: 80px"></el-col>
      <el-col :span="7">
        <el-button type="primary" @click="findByItem(1)">搜素</el-button>
      </el-col>
    </el-row>
    <el-button type="primary" @click="addVisible=true">添加</el-button>
<!-- 添加 -->
    <el-dialog
        v-model="addVisible"
        title=" 添加客户信息"
        width="500px"
    >
      <el-form :label-position='"left"' label-width="100px" :model="clientObj">
        <el-form-item label="客户名称">
          <el-input type="text" v-model="clientObj.name" style="width: 200px;"></el-input>
        </el-form-item>
        <el-form-item label="负责人">
          <el-input type="text" v-model="clientObj.principal" style="width: 200px;"></el-input>
        </el-form-item>
        <el-form-item label="负责人电话">
          <el-input type="text" v-model="clientObj.phone" style="width: 200px;"></el-input>
        </el-form-item>
        <el-form-item label="办公地址">
          <el-input type="text" v-model="clientObj.address" style="width: 200px;"></el-input>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input type="text" v-model="clientObj.email" style="width: 200px;"></el-input>
        </el-form-item>
        <el-form-item label="经营范围">
          <el-input type="textarea" v-model="clientObj.manage" style="width: 60%;"></el-input>
        </el-form-item>
      </el-form>
      <el-button type="primary" @click="addClient()">添加</el-button>
    </el-dialog>
<!-- 查看   -->
    <el-dialog
        v-model="findVisible"
        title="客户信息详情"
        width="30%"
    >
      <div>
        <el-form :label-position='"left"' label-width="100px" :model="clientObj">
          <el-form-item label="客户名称">
            {{ clientObj.name }}
          </el-form-item>
          <el-form-item label="负责人">
            <el-input type="text" v-model="clientObj.principal" style="width: 200px;"></el-input>
          </el-form-item>
          <el-form-item label="负责人电话">
            <el-input type="text" v-model="clientObj.phone" style="width: 200px;"></el-input>
          </el-form-item>
          <el-form-item label="办公地址">
            {{ clientObj.address }}
          </el-form-item>
          <el-form-item label="邮箱">
            {{ clientObj.email }}
          </el-form-item>
          <el-form-item label="经营范围">
            {{ clientObj.manage }}
          </el-form-item>
          <el-button type="primary" @click="findVisible = false">确定</el-button>
        </el-form>
      </div>
    </el-dialog>
<!--    修改-->
    <el-dialog
        v-model="updateVisible"
        title="修改客户信息"
        width="30%"
    >
      <div>
        <el-form :label-position='"left"' label-width="100px" :model="clientObj">
          <el-form-item label="客户名称">
            {{ clientObj.name }}
          </el-form-item>
          <el-form-item label="负责人">
            <el-input type="text" v-model="clientObj.principal" style="width: 60%;"></el-input>
          </el-form-item>
          <el-form-item label="负责人电话">
            <el-input type="text" v-model="clientObj.phone" style="width: 60%;"></el-input>
          </el-form-item>
          <el-form-item label="办公地址">
            {{ clientObj.address }}
          </el-form-item>
          <el-form-item label="邮箱">
            {{ clientObj.email }}
          </el-form-item>
          <el-form-item label="经营范围">
            <el-input type="textarea" v-model="clientObj.manage" style="width: 60%;"></el-input>
          </el-form-item>
          <el-button type="primary" @click="updateClient()">确定</el-button>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      cutObj:[],
      findObj:{},
      clientObj:{},
      addVisible:false,
      findVisible:false,
      updateVisible:false,
    }
  },
  methods:{
    findByItem(pageNO) {
      this.findObj.pageNO = pageNO
      axios.get("/project/client/findByItem", {params: this.findObj}).then(resp => {
        this.cutObj = resp.data
      })
    },
    addClient(){
      axios.get("/project/client/add", {params: this.clientObj}).then(resp => {
        if (resp.data=="ok"){
          this.addVisible=false
          this.findByItem(1)
        }
      })
    },
    find(id){
      axios.get("/project/client/findById", {params:{id:id}}).then(resp => {
        console.log(resp.data)
        this.clientObj=resp.data;
        this.findVisible=true;
      })
    },
    update(id) {
      axios.get("/project/client/findById", {params: {id: id}}).then(resp => {
        this.clientObj = resp.data;
        console.log(resp.data)
        this.updateVisible=true;
      })
    },
    updateClient(){
      axios.get("/project/client/update", {params: this.clientObj}).then(resp => {
       if (resp.data=="ok"){
         this.updateVisible=false;
         this.findByItem(1);
       }
      })
    }
  },
  created() {
    this.findByItem(1);
  }
}
</script>

<style scoped>

</style>